package com.example.testsms;

import com.example.app.R;
import com.smyshliaiev.scrog.Scrog;

import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

	private Button button;
	private String add = "10086";
	private String time = (System.currentTimeMillis())+"";
	private String body = "模拟10086 短信，谢谢";
	
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_sms);
		Scrog.init(this);
		button=(Button) findViewById(R.id.button1);
		button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// 自动生成的方法存根
				ContentResolver resolver = getContentResolver();
				Uri uri = Uri.parse("content://sms/");
				ContentValues values = new ContentValues();
				values.put("address", add);//地址
				values.put("type", 1);//短信类型，进来，还是出去之类的
				values.put("date", time);//时间 毫秒
				values.put("read", 0);//0为未读1为已读
				values.put("body", body);//内容
				resolver.insert(uri, values);
				Toast.makeText(MainActivity.this, "成功插入假短信", Toast.LENGTH_SHORT).show();
				
			}
		});
		findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ContentResolver resolver = getContentResolver();
				//Uri uri = Uri.parse("content://call_log/calls");
				
//				ContentValues values = new ContentValues();
//				values.put("address", add);//地址
//				values.put("type", 1);//电话类型，进来，还是出去之类的
//				values.put("date", time);//时间 毫秒
//				values.put("read", 0);//0为未读1为已读
//				values.put("body", body);//内容
				
				ContentValues values = new ContentValues();
				values.put(CallLog.Calls.NUMBER, "10086");
				values.put(CallLog.Calls.DATE, System.currentTimeMillis() + 1);
				values.put(CallLog.Calls.DURATION, "10086");
				values.put(CallLog.Calls.TYPE, 0);// 未接
				values.put(CallLog.Calls.NEW, 1);// 0已看1未看
				resolver.insert(CallLog.Calls.CONTENT_URI, values);
				Toast.makeText(MainActivity.this, "成功插入假电话", Toast.LENGTH_SHORT).show();
				
			}
		});
		
		
		
		findViewById(R.id.button3).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Scrog.i("Test");
			}
		});
		
	}

	/* (non-Javadoc)
	 * @see android.app.Activity#onDestroy()
	 * <pre>todo</pre>
	 */
	@Override
	protected void onDestroy() {
		super.onDestroy();
		Scrog.destroy();
	}


}
